<?	

	class PaginationClassFrontAjax

	{

		var $item_per_page;

		var $shift_page_no;

		var $display_page_no;		

		

		var $ERROR = "";

		

		function clear_error()

		{

			$this->ERROR = "";

		}

		function PaginationClassFrontAjax($item_per_page,$display_page_no,$shift_page_no)

		{			

			$this->item_per_page=$item_per_page;

			$this->shift_page_no=$shift_page_no;

			$this->display_page_no=$display_page_no;										

		}

		function PaginationFrontAjax($function_name,$sql,$page_name,$CategoryID="",$CategoryName="")

		{				

			global $from;

			global $from_page;

			if(empty($from))

			{

				$from=0;

			}

			if(empty($from_page))

			{

				$from_page=1;

			}

			if(!empty($CategoryID))

				$category_link="&$CategoryName=".$CategoryID;			

				

			$totrec=mysql_num_rows(mysql_query($sql));

			if($totrec>0)

			{

				if($totrec>$this->item_per_page)

				{

					$prev=$from-$this->item_per_page;

					$next=$from+$this->item_per_page;					

					if($totrec-($this->item_per_page*$this->display_page_no) && $from_page>1)

					{
					   

						$navigation.= "<li><a href='#' onclick=\"$function_name('$page_name&action=list_paginate&from=".$from."&amp;from_page=".($from_page-$this->shift_page_no).$category_link."')\" >Previous</a></li>";



					}

					else

					{

						$navigation.= "";

					}					

					for($i=1; $i<=ceil($totrec/$this->item_per_page);$i++)

					{

						if($i>=$from_page && $i<=($from_page+$this->display_page_no-1))

						{

							$num_len=strlen($i);							

							if((($from/$this->item_per_page)+1)==$i)

							{

								$navigation.= "<li><a href='#' class='pageselect'>".$i."</a></li> ";

							}

							else

							{

								$startval=($i-1)*$this->item_per_page;

								$navigation.= "<li><a href='#' onclick=\"$function_name('$page_name&action=list_paginate&amp;from=".$startval."&amp;from_page=".$from_page.$category_link."'); return false;\" >".$i."</a></li> ";

							}

						}

					}									

					if($totrec-($this->item_per_page*$this->display_page_no) && ($totrec>(($from_page+$this->display_page_no-1)*$this->item_per_page)))

					{

						$navigation.= "<li><a href='#' onClick=\"$function_name('$page_name&action=list_paginate&from=".$from."&amp;from_page=".($from_page+$this->shift_page_no).$category_link."')\" >Next</a></li>";

					}

					else

					{

						$navigation.= " ";

					}

				}

			}

			$limit_sql=" LIMIT $from , ".$this->item_per_page;

			$sql=$sql.$limit_sql;

			

			$num=mysql_num_rows(mysql_query($sql));

			

			$totalrecord="<b>Total Records:</b> ".$totrec." <b><br>(Showing</b> ".($from+1)." <b>To</b> ".($from+$num)."<b>)</b> ";

			$return_arr=array($sql,$navigation,$totalrecord,$totrec);

			return $return_arr;							

		}

		

	}	

?>